package functions;

import main.ContingencyTable;

public class KlosgenFunction extends GeneralFunction {

	public KlosgenFunction(String name) {
		super(name);
	}

	@Override
	public double calculate(ContingencyTable t) {
		return Math.sqrt(pXY(t)) * Math.max(pYgX(t) - pY(t), pXgY(t) - pX(t));
	}
	
	private double pXY(ContingencyTable t) {
		return t.f11() / t.N();
	}
	
	private double pX(ContingencyTable t) {
		return t.f1p() / t.N();
	}
	
	private double pY(ContingencyTable t) {
		return t.fp1() / t.N();
	}
	
	private double pXgY(ContingencyTable t) {
		return t.f11() / t.fp1();
	}

	private double pYgX(ContingencyTable t) {
		return t.f11() / t.f1p();
	}

}
